package com.gxa.jjty.admin.controller;

import com.github.pagehelper.PageInfo;
import com.gxa.jjty.admin.service.TorderService;
import com.gxa.jjty.core.common.JsonResult;

import com.gxa.jjty.core.pojo.Torder;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import lombok.extern.log4j.Log4j2;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Log4j2
@RestController
@RequestMapping("/refund")
@Api(tags = "退款介入接口")

public class RefundController {

    @Autowired
    TorderService torderService;
    @PostMapping("/select")
    @ApiOperation("退款订单查询")
    public Map select(String orderState){
        Torder torder = new Torder();
        torder.setRefundOrder("退款订单");
        List<Torder> select = torderService.select(torder);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(select);
        return jsonResult.getDataMap();

    }
    @PostMapping("/update")
    @ApiOperation("订单退款处理")
    public Map<String,Object> update(@RequestBody Torder torder) throws IllegalAccessException {
        Integer integer = torderService.updateById(torder);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        return jsonResult.getDataMap();
    }

    @PostMapping("/selectByPage")
    @ApiOperation("退款订单分页查询")
    public Map<String,Object> selectByPage( Integer page, Integer size) throws IllegalAccessException {
        Torder torder = new Torder();
        torder.setRefundOrder("退款订单");
        PageInfo<Torder> torderPageInfo = torderService.selectByPage(page, size,torder);
        JsonResult jsonResult = new JsonResult();
        jsonResult.setCode("1");
        jsonResult.setData(torderPageInfo);
        return jsonResult.getDataMap();
    }

  @PostMapping("/selectByField")
  @ApiOperation("根据条件筛选查询")
  @ApiImplicitParams({
          @ApiImplicitParam(name = "from", value = "开始时间(可选)"),
          @ApiImplicitParam(name = "to", value = "结束时间(可选)"),
          @ApiImplicitParam(name = "orderNumber", value = "编号(可选)"),
          @ApiImplicitParam(name = "orderUser", value = "用户(可选)"),
          @ApiImplicitParam(name = "phyName", value = "陪护员(可选)"),
          @ApiImplicitParam(name = "payType", value = "状态(可选)"),
          @ApiImplicitParam(name = "page", value = "页码(必须)"),
          @ApiImplicitParam(name = "size", value = "每页显示条数(必须)")

  })
  public Map selectByField(Date from, Date to, String orderNumber, String orderUser, String phyName, String payType, Integer page, Integer size) throws IllegalAccessException {
      Torder torder = new Torder();
      torder.setOrderNumber(orderNumber);
      torder.setOrderUser(orderUser);
      torder.setPhyName(phyName);
      torder.setPayType(payType);
      torder.setRefundOrder("退款订单");
      PageInfo<Torder> torderPageInfo = torderService.selectOrderByField(from, to, torder, page, size);
      JsonResult jsonResult = new JsonResult();
      jsonResult.setCode("1");
      jsonResult.setData(torderPageInfo);
      return jsonResult.getDataMap();
  }


}
